package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class AddSubject {
    public static void main(String[] args) {
        Connection connection = null;
        Statement st = null;

        try {
            connection = DBUtil.getConnection();
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入课程名称，课时，和年级号：");
            String gname = sc.next();
            int hour = sc.nextInt();
            long gid = sc.nextLong();
            String sql = "insert into s_subject(subjectname,classhour,gradeid)" +
                    "values('" + gname + "'," + hour + "," + gid + ")";
            System.out.println(sql);
            st = connection.createStatement();
            int i = st.executeUpdate(sql);
            System.out.printf("增加了%d条", i);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(null,st,connection);
        }

    }
}
